package com.wdemo.controller;

import com.wdemo.pojo.vo.ChatPdfVo;
import com.wdemo.service.ChatPdfService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import reactor.core.publisher.Flux;

import java.io.IOException;

/**
 * @ClassName ChatFileController
 * @Description TODO
 * @Author WDEMO
 * @Date 2025/9/2 1:55
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/ai/pdf")
@RequiredArgsConstructor
public class ChatPdfController {

    private final ChatPdfService chatPdfService;

    @PostMapping("/upload/{chatId}")
    public ChatPdfVo uploadPdf(@RequestParam("file") MultipartFile file, @PathVariable("chatId") String chatId) throws IOException {
        ChatPdfVo chatPdfVo = chatPdfService.uploadPdfToAliyun(file, chatId);
        return chatPdfVo;
    }

    @GetMapping("/file/{chatId}")
    public ResponseEntity<Resource> downloadPdf(@PathVariable("chatId") String chatId){
        ResponseEntity<Resource> resource = chatPdfService.downloadPdfByAliyun(chatId);
        return resource;
    }

    @GetMapping("/chat")
    public Flux<String> chat(@RequestParam("prompt") String prompt, @RequestParam("chatId") String chatId){
       return chatPdfService.chat(prompt,chatId);

    }
}
